package net.mcreator.infinite_storage.procedure;

import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.Entity;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.advancements.Advancement;

import net.mcreator.infinite_storage.ElementsInfiniteStorageMod;

import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;

@ElementsInfiniteStorageMod.ModElement.Tag
public class ProcedureInfiniteCoreRightClick extends ElementsInfiniteStorageMod.ModElement {
	public ProcedureInfiniteCoreRightClick(ElementsInfiniteStorageMod instance) {
		super(instance, 48);
	}
	static Map<String, Object> $_dependencies = new HashMap<>();
	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			return;
		}
		if (dependencies.get("itemstack") == null) {
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		ItemStack itemstack = (ItemStack) dependencies.get("itemstack");
		NBTTagCompound InfiniteBag = entity.getEntityData().getCompoundTag("InfiniteBag");
		if ((!InfiniteBag.getBoolean("InfiniteBagOn"))) {
			if (entity instanceof EntityPlayer && !entity.world.isRemote) {
				((EntityPlayer) entity).sendStatusMessage(
						new TextComponentString((new TextComponentTranslation("Infinite_core.msg.a").getUnformattedComponentText())), (false));
			}
			if (entity instanceof EntityPlayer && !entity.world.isRemote) {
				((EntityPlayer) entity).sendStatusMessage(
						new TextComponentString((new TextComponentTranslation("Infinite_core.msg.b").getUnformattedComponentText())), (false));
			}
			if (entity instanceof EntityPlayerMP) {
				Advancement _adv = ((MinecraftServer) ((EntityPlayerMP) entity).mcServer).getAdvancementManager()
						.getAdvancement(new ResourceLocation("infinite_storage:infinite_bag_get"));
				AdvancementProgress _ap = ((EntityPlayerMP) entity).getAdvancements().getProgress(_adv);
				if (!_ap.isDone()) {
					Iterator _iterator = _ap.getRemaningCriteria().iterator();
					while (_iterator.hasNext()) {
						String _criterion = (String) _iterator.next();
						((EntityPlayerMP) entity).getAdvancements().grantCriterion(_adv, _criterion);
					}
				}
			}
			((itemstack)).shrink((int) 1);
			InfiniteBag.setBoolean("InfiniteBagOn", (true));
		} else {
			if (entity instanceof EntityPlayer && !entity.world.isRemote) {
				((EntityPlayer) entity).sendStatusMessage(
						new TextComponentString((new TextComponentTranslation("Infinite_core.msg.c").getUnformattedComponentText())), (false));
			}
		}
		entity.getEntityData().setTag("InfiniteBag", InfiniteBag);
	}
}
